package com.updateImage;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Coordinate;

import java.awt.*;
import java.awt.image.BufferedImage;

public class test4 {
    public static void main(String[] args){
        try {
            int width = 750;
            int height = 1334;

            BufferedImage backgroundImage = Thumbnails.of("F:\\image\\1.png").size(100, 100).asBufferedImage( );
            BufferedImage materialImage = Thumbnails.of("F:\\image\\2.png").size(100, 100).asBufferedImage( );
            BufferedImage doorImage = Thumbnails.of("F:\\image\\3.png").size(100, 100).asBufferedImage( );
            BufferedImage qrImage = Thumbnails.of("F:\\image\\4.png").size(100, 100).asBufferedImage( );


            BufferedImage textImage = Thumbnails.of(handleTextWaterMark( )).size(400,400).asBufferedImage();
            Thumbnails.of("F:\\image\\5.png").size(width, height)
                    .watermark(new Coordinate(100, 100),backgroundImage,1f)
                    .watermark(new Coordinate((int)(width*0.6), 0),materialImage,1f)
                    .watermark(new Coordinate((int)(width*0.4),(int)(height*0.29)),doorImage,1f)
                    .watermark(new Coordinate((int)(width*0.6),(int)(height*0.74)),qrImage,1f)
                    .watermark(new Coordinate((int)(width*0.08),(int)(height*0.74)), textImage, 1f)
                    .toFile("F:\\image\\result.png");


        } catch (Exception e) {
            e.printStackTrace( );
        }
    }
    /**
     * @throws
     * @description 操纵文字型水印
     */
    private static BufferedImage handleTextWaterMark( ) {
// 设置文字样式
        Font font = new Font("微软雅黑", Font.BOLD, 24);
        //创建缓存图
        BufferedImage image = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
        //生成图片
        Graphics2D g = image.createGraphics( );
        //设置图片透明度为透明
        image = g.getDeviceConfiguration( ).createCompatibleImage(400, 400, Transparency.TRANSLUCENT);

        //设置文本 距离
        int y = 0;
        int distTop = 45;

        g = image.createGraphics( );
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(Color.black);
        g.setFont(font);

        g.drawString("Avignon", 5, y += distTop);

        g.setColor(new Color(102,102,102));
        g.setFont(new Font("微软雅黑", Font.CENTER_BASELINE, 20));
        g.drawString("1400/42K/24KS", 5, y += distTop);
        g.drawString("材质：不锈钢", 5, y += distTop);
        g.drawString("颜色：古铜色", 5, y += distTop);
        g.drawString("专利：AMTWAVAVG", 5, y += distTop);

        g.dispose( );
        return image;
    }
}
